var logger = null;
var consoleService = null;

function debug_init(){
	consoleService = Components.classes["@mozilla.org/consoleservice;1"]
                                 .getService(Components.interfaces.nsIConsoleService);
}

function var_dump(sourceName, object, opt_level){
  if(typeof(object) == "undefined")
    return false;
  var msg = "null";
  if(object != null)
    msg = object.toJSONString();
  debug(sourceName + msg, opt_level);
}

function debug(str, opt_level){
  if(str == null) return;
  //if(str.length > 600) str = str.substr(0, 300);
  switch(DEBUG){
    case "console":
      if(consoleService == null) debug_init();
      myLogToConsole(str,opt_level);
      break;
    case "dump":
      dump(str);
      break;
    case "alert":
      alert(str);
      break;
    default :
      break;
  }
}

function myLogToConsole(aMessage,  aFlags)
{
  var consoleService = Components.classes["@mozilla.org/consoleservice;1"]
                                 .getService(Components.interfaces.nsIConsoleService);
  var scriptError = Components.classes["@mozilla.org/scripterror;1"]
                              .createInstance(Components.interfaces.nsIScriptError);
  scriptError.init(aMessage, "", "", "",
                   "", aFlags, "");
  consoleService.logMessage(scriptError);
}
